package com.fund.datacopy.task.thread;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.fund.datacopy.bean.Group;
import com.fund.datacopy.conf.Configure;

public class TaskPool {
	public void copy(List<String> groupNames) throws Exception {
		if (CollectionUtils.isEmpty(groupNames)) {
			System.out.println(" group  name is miss...");
			return;
		}
		Configure.init();
		Collection<Group> groups = Configure.getAllSettings();

		if (CollectionUtils.isNotEmpty(groups)) {
			Iterator<Group> it = groups.iterator();
			while (it.hasNext()) {
				Group g = (Group) it.next();
				if (groupNames.contains(g.getName())) {
					execute(g);
				}
			}
		}
	}

	public void copy(String group) throws Exception {
		List<String> gr = new ArrayList();
		gr.add(group);
		copy(gr);
	}

	public void execute(Group g) {
		Thread worker = new Thread(new Allocater(g));
		try {
			worker.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		TaskPool pool = new TaskPool();
		try {
			pool.copy("fund.recomm_valchg");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
